﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Frame.Lib.Common
{
    public sealed class AppSetting
    {
        public static string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
            }
        }


        ///// <summary>
        ///// 数据库框架
        ///// </summary>
        //public static string DBSchema
        //{
        //    get
        //    {
        //        string schema = System.Configuration.ConfigurationManager.AppSettings["DBSchema"] ?? "";
        //        if (schema != "")
        //        {
        //            schema += ".";
        //        }
        //        return schema;
        //    }
        //}

        public static int PageSize
        {
            get
            {
                string strPageSize = System.Configuration.ConfigurationManager.AppSettings["PageSize"];

                try
                {
                    return int.Parse(strPageSize);
                }
                catch
                {
                    return 10;
                }

            }
        }

        /// <summary>
        /// 当新增用户时，把他添加到一个默认角色，一般些角色为系统的普通员工角色
        /// </summary>
        public static string UserDefaultRoleID
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["UserDefaultRoleID"];
            }
        }

        /// <summary>
        /// 当新增模块时，把此模块添加到一个默认角色，一般此角色为系统的管理员角色
        /// </summary>
        public static string ModuleDefaultRoleID
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ModuleDefaultRoleID"];
            }
        }

        /// <summary>
        /// 附件存放的磁盘物理路径
        /// </summary>
        public static string AttachPath
        {
            get
            {
                string path = System.Configuration.ConfigurationManager.AppSettings["AttachPath"];
                if (path != null && path != "")
                {
                    return path.TrimEnd('\\') + "\\";
                }
                else
                {
                    //string webAppPath = System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/');

                    //return System.Web.HttpContext.Current.Server.MapPath(webAppPath + "/Attachs/").TrimEnd('\\') + "\\";

                    return AppDomain.CurrentDomain.BaseDirectory + "Attachs\\";
                }
            }
        }

        /// <summary>
        /// 共享大文件上传的物理路径
        /// </summary>
        public static string ShareFilePath
        {
            get
            {
                string path = System.Configuration.ConfigurationManager.AppSettings["UploadPath"];
                if (path != null && path != "")
                {
                    return path.TrimEnd('\\') + "\\";
                }
                else
                {
                    string webAppPath = System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/');

                    return System.Web.HttpContext.Current.Server.MapPath(webAppPath + "/ShareFiles/").TrimEnd('\\') + "\\";
                }
            }

        }

        /// <summary>
        /// 用户图片存放的虚拟目录
        /// </summary>
        public static string UserImagePath
        {
            get
            {
                string path = System.Configuration.ConfigurationManager.AppSettings["UserImagePath"];
                if (path != null && path != "")
                {
                    return path.TrimEnd('/') + "/";
                }
                else
                {
                    return "UserImages/";
                }
            }
        }

        /// <summary>
        /// 访问图片的域名，用于CMS里文章的图片替换
        /// </summary>
        public static string ImageDomain
        {
            get
            {
                string imageDomain = System.Configuration.ConfigurationManager.AppSettings["ImageDomain"];
                if (string.IsNullOrEmpty(imageDomain))
                {
                    return "";
                }
                else
                {
                    return imageDomain.TrimEnd('/');
                }
            }

        }


        /// <summary>
        /// 工作流图片路径
        /// </summary>
        public static string FlowImagePath
        {
            get
            {
                string path = System.Configuration.ConfigurationManager.AppSettings["FlowImagePath"];
                if (path != null && path != "")
                {
                    return path.TrimEnd('/') + "/";
                }
                else
                {
                    return "FlowImagePath/";
                }
            }
        }

        public static int FreindLinkImageSize
        {
            get
            {
                string size = System.Configuration.ConfigurationManager.AppSettings["FreindLinkImageSize"];
                if (size != null && size != "")
                {
                    return int.Parse(size);
                }
                else
                {
                    return 150;
                }
            }
        }

        /// <summary>
        /// 电子小秘书专用
        /// </summary>
        public static string OAUrl
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["OAUrl"];
            }
        }

        public static bool IsDebug
        {
            get
            {
                string isDebug = System.Configuration.ConfigurationManager.AppSettings["IsDebug"];
                if (isDebug != null && isDebug != "")
                {
                    return Convert.ToBoolean(isDebug);
                }
                else
                {
                    return false;
                }
            }
        }

        /// <summary>
        /// 自定议的字典项
        /// </summary>
        public static string DictItem
        {
            get
            {
                string dictItem = System.Configuration.ConfigurationManager.AppSettings["DictItem"];
                if (string.IsNullOrEmpty(dictItem))
                {
                    dictItem = "Frame.Lib.Enums.DictItem,Frame.Lib";
                }
                return dictItem;
            }
        }

        /// <summary>
        /// 扩展的系统角色枚举,枚举值要小于-2，如Jzy.Common.InternalRole,Jzy.Common
        /// </summary>
        public static string SystemRole
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SystemRole"];
            }
        }


        /// <summary>
        /// 调度更新数据周期，默认为5分钟
        /// </summary>
        public static int DispatchUpdateInterval
        {
            get
            {
                string tmp = System.Configuration.ConfigurationManager.AppSettings["DispatchUpdateInterval"];
                if (string.IsNullOrEmpty(tmp))
                {
                    return 1000 * 60 * 5;
                }
                else
                {
                    return int.Parse(tmp);
                }
            }
        }


        public static bool MultiCompany
        {
            get
            {
                string tmp = System.Configuration.ConfigurationManager.AppSettings["MultiCompany"];
                if (string.IsNullOrEmpty(tmp))
                {
                    return false;
                }
                else
                {
                    if (tmp.ToLower() == "true")
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
    }
}
